package com.yonyou.jrmob.application.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.yonyou.jrmob.application.R;

import cn.bingoogolapple.titlebar.BGATitleBar;
import jrmob.yonyou.com.commonlib.app_config_tool.tool.base.StatusBarUtil;
import jrmob.yonyou.com.commonlib.baseui.base.BaseActivityMob_lib;
import jrmob.yonyou.com.commonlib.vo.AppVO_ap;

public class AppDetailActivity extends BaseActivityMob_lib {
    private BGATitleBar titleBar;
    private ImageView appIcon;
    private TextView appName;
    private TextView appNum;
    private ImageView buy;
    private TextView detail;
    private AppVO_ap mAppVO_ap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_detail);
        initView();
        initData();
        initTitleBar();
        StatusBarUtil.StatusBarLightMode(this);
        StatusBarUtil.setStatusBarColor(this,R.color.white);
    }

    private void initTitleBar() {
        titleBar.setDelegate(new BGATitleBar.Delegate() {
            @Override
            public void onClickLeftCtv() {
                finish();
            }

            @Override
            public void onClickTitleCtv() {

            }

            @Override
            public void onClickRightCtv() {

            }

            @Override
            public void onClickRightSecondaryCtv() {

            }
        });
    }

    @Override
    public void initView() {
        titleBar = (BGATitleBar) findViewById(R.id.app_detail_title_bar);
        appIcon = (ImageView) findViewById(R.id.app_detail_app_icon);
        appName = (TextView) findViewById(R.id.app_detail_name);
        appNum = (TextView) findViewById(R.id.app_detail_num);
        detail = (TextView) findViewById(R.id.app_detail_detail);
        buy = (ImageView) findViewById(R.id.app_detail_buy);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            try {
                mAppVO_ap = (AppVO_ap) bundle.getSerializable("data");
            } catch (Exception e) {
                e.printStackTrace();
                Snackbar.make(buy, "数据异常", Snackbar.LENGTH_LONG).show();
            }
            if (mAppVO_ap == null) {
                Snackbar.make(buy, "数据异常", Snackbar.LENGTH_LONG).show();
                return;
            }
        } else {
            Snackbar.make(buy, "数据异常", Snackbar.LENGTH_LONG).show();
            return;
        }
        String appNameString = mAppVO_ap.getApp_name();
        appName.setText(appNameString);
        titleBar.setTitleText(appNameString);
        String strDetail = "";
        switch (mAppVO_ap.getApp_code()) {
            case "XDA":
                strDetail = getString(R.string.app_detail_xda);
                break;
            case "BX":
                strDetail = getString(R.string.app_detail_bx);
                break;
            case "RZ":
                strDetail = getString(R.string.app_detail_rz);
                break;
            case "BL":
                strDetail = getString(R.string.app_detail_bl);
                break;
            case "XD":
                strDetail = getString(R.string.app_detail_xd);
                break;
            case "YX":
                strDetail = getString(R.string.app_detail_yx);
                break;
            case "BD":
                strDetail = getString(R.string.app_detail_bd);
                break;
            case "OF":
                strDetail = getString(R.string.app_detail_of);
                break;
        }
        detail.setText(strDetail);
        Glide.with(AppDetailActivity.this)
                .load(mAppVO_ap.getLogo_url())
                .crossFade()
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(appIcon);
    }
}
